<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>注册</title>
    <%- include common %>
</head>

<body>
    <%- include('head',{title:'register',username:''})%>
        <div class="container">
            <h2 class="text-info">注册 - register </h2>
            <div class="row">
                <div class="col-md-4 ">
                    <!-- <form action="/users/register/submit" method="POST" > -->
                    <div class="form-group">
                        <label for="username">用户名</label>
                        <input type="text" name="username" class="form-control" id="username" placeholder="Username">
                    </div>
                    <div class="form-group">
                        <label for="mobile">手机号码</label>
                        <input type="tel" name="mobile" class="form-control" id="mobile" placeholder="Telephone">
                    </div>
                    <div class="form-group">
                        <label for="password">密码</label>
                        <input type="password" name="password" class="form-control" id="password"
                            placeholder="Password">
                    </div>
                    <div class="form-group">
                        <label for="confirm_password">确认密码</label>
                        <input type="password" name="confirm_password" class="form-control" id="confirm_password"
                            placeholder="Confirm Password">
                    </div>
                    <button type="button" id="btn" class="btn btn-warning">注册</button>
                    <button type="reset" class="btn btn-danger">重置</button>

                    <!-- </form> -->
                </div>
            </div>
        </div>
        <%- include foot %>
</body>
<script>
    $('#btn').click(function () {
        $.ajax({
            url: '/users/register',
            type: 'POST',
            data: {
                username: $('#username').val(),
                mobile: $('#mobile').val(),
                password: $('#password').val(),
            },
            success(res) {
                alert(res.msg);
                if (res.type) {
                    location.href = `/login?username=${res.regData.username}&password=${res.regData.password}`
                } else {
                    location.reload();
                }
            }
        })
    })
</script>

</html>